function LastDateArryorder(){
    var form = document.getElementById('form');
    if(LastDateArry.value=="0")
        document.getElementById("LastDateArry").value = "1";
    else
        document.getElementById("LastDateArry").value = "0";
    console.log(LastDateArry.value);
    form.submit();
}

function searchState() {
    //var searchkeyword = $('input[name=searchkeyword]').val();
    var searchkeyword=document.getElementById("searchKeyword").value
    console.log(searchkeyword);
    if (keyword !== "") {
        var form = document.getElementById('form');
        document.getElementById("keyword").value = searchkeyword;
        console.log(searchkeyword);
        document.getElementById("pageNum").value = "1";
        form.action="/admin/searchBykw"
        form.submit();
    }
}
function firstPage(){
    var form = document.getElementById('form');
    document.getElementById("pageNum").value = "1";

    form.submit();
}
function lastPage(){
    var form = document.getElementById('form');
    document.getElementById("pageNum").value = document.getElementById("totalPages").value;

    console.log( document.getElementById("pageNum").value);
    console.log( document.getElementById("totalPages").value);
    form.submit();
}
function nextPage(){
    var form = document.getElementById('form');
    var totalPages=document.getElementById("totalPages");
    var pageNum=document.getElementById("pageNum");

    pageNum.value=parseInt(pageNum.value)+1;
    if(pageNum.value>=totalPages.value)
        pageNum.value=totalPages.value;
    console.log(pageNum.value)
        form.submit();
}
function prePage(){
    var form = document.getElementById('form');
    var pageNum=document.getElementById("pageNum");

    pageNum.value=pageNum.value-1;
    if(pageNum.value<=0)
        pageNum.value=1;
        form.submit();
}
function searchPage(){
    var form = document.getElementById('form');
    var pageNum=document.getElementById("searchPageNum");
    var totalPages=document.getElementById("totalPages").value;
    if (pageNum.value>totalPages)
        pageNum.value=totalPages;
    if(pageNum.value<=0)
        pageNum.value=1;
    document.getElementById("pageNum").value=pageNum.value;
    form.submit();
}
function updateAccount(id,isLogin){
    var form=document.getElementById("form");
    var input = document.createElement("input");
    input.setAttribute("type",'hidden') ;
    input.setAttribute("name",'UserId') ;
    input.setAttribute("value", id) ;
    input.setAttribute("type",'hidden') ;
    input.setAttribute("name1",'login') ;
    input.setAttribute("value1", isLogin) ;
    form.appendChild(input);
    console.log(input);
    form.action="/admin/user"
    form.submit();
}
function searchAccount() {
    var searchkeyword=document.getElementById("searchKeyword").value
    console.log(searchkeyword);
    if (searchkeyword !== "") {
        var form = document.getElementById('form');
        document.getElementById("keyword").value = searchkeyword;
        document.getElementById("pageNum").value = "1";
        form.action="/admin/searchuser"
        form.submit();
    }
}

function deleteAccount(obj){
    var r=window.confirm("确定要删除吗");
    if(r==true){
    var id=obj.id.replace('delete','');
    var form=document.getElementById("form");
    var input1 = document.createElement("input");
    input1.setAttribute("type", 'hidden');
    input1.setAttribute("name", 'UserId');
    input1.setAttribute("value", id);
    form.appendChild(input1);
    form.action="/admin/deleteUser";
    form.submit();
    }
    else{
        this.parent.close()
    }
}
function backState() {
    var form = document.getElementById('form');
    document.getElementById("state").value = "1";
    console.log(state);
    form.action="/admin/user";
    form.submit();
}
function backmain() {
    var form = document.getElementById('form');
    form.action="/admin/user";
    form.submit();
}
function backnow() {
    var form = document.getElementById('form');

    document.getElementById("state").value = "1";

    console.log(state);
    form.action="/admin/show";
    form.submit();
}
function ableUpdate(obj){
    document.getElementById(obj.id).innerHTML="保存"
    document.getElementById("login"+obj.id).disabled="";
    document.getElementById("id"+obj.id).disabled="";
    document.getElementById("name"+obj.id).disabled="";
    document.getElementById("sex"+obj.id).disabled="";
    document.getElementById("address"+obj.id).disabled="";
    document.getElementById("phone"+obj.id).disabled="";
    console.log(obj);
    document.getElementById(obj.id).onclick = function(){
        updateAccount(obj.id,obj.isLogin);
    };

}
